<?php

namespace App\Http\Controllers\Lost;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;
use LostService;


class PublishController extends BaseController
{

    public function publish(Request $request)
    {
        $this->validate($request, [
            'description' => 'required',
            'shortPhone' => ['required_without:cellphone', 'regex:/^[3-8][0-9]{2,5}$/'],
            'cellphone' => ['required_without:shortPhone', 'regex:/^(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}|170[059]\d{7}$/'],
            'number' => 'digits_between:10,12'
        ], [
            'shortPhone.required_without' => '长号以及短号至少填写一个',
            'cellphone.required_without' => '',
            'cellphone.regex' => '长号格式不正确',
            'shortPhone.regex' => '短号格式不正确',
            'number.digits_between' => '学号长度不正确'
        ]);
        LostService::publish(
            \Auth::guard('wechat')->user()->open_id,
            $request->get('media_id'),
            $request->get('description'),
            $request->get('number'),
            $request->get('shortPhone'),
            $request->get('cellphone')
        );

        return $this->ok('发布成功');
    }
}
